package com.ereport.controller.plannerController;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ereport.dao.AdminExeBudgetDAO;
import com.ereport.dao.MyBudgetDAO;
import com.ereport.entity.AdminExeBudget;
import com.ereport.entity.Executives;
import com.ereport.util.Constants;

@Controller
@RequestMapping("/mybudget")
public class MyBudgetController {

	@RequestMapping("/open.do")
	public ModelAndView open(HttpServletRequest req,HttpSession session,ModelAndView model){
		Executives ex=(Executives)session.getAttribute("loginUser");
		if(ex==null){
			model.setViewName("/jsp/login.jsp");
			return model;
		}
		
		model.setViewName("/jsp/myBudget.jsp");
		return model;
	}
	@RequestMapping(value="/getMyBudget.do", method=RequestMethod.GET)
	public @ResponseBody
	String getExeBudget(HttpServletRequest req,HttpSession session,ModelAndView model){
		Executives ex=(Executives)session.getAttribute("loginUser");
		System.out.println(ex.getId());
		String frmYear=req.getParameter("fromYear");
		String toYear=req.getParameter("toYear");
		String fyear=frmYear+"-"+toYear;
		MyBudgetDAO mbdao=new MyBudgetDAO();
		
		List<AdminExeBudget> aeblist=null;
		try {
			aeblist=mbdao.getMyBudget(ex.getId(),fyear);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		StringBuilder sb=new StringBuilder();
		if(aeblist!=null){
		for(int i=0;i<aeblist.size();i++){
			double te=aeblist.get(i).getTe();
			double cp=aeblist.get(i).getCp();
			double fe=aeblist.get(i).getFe();
			sb.append(te+"/"+cp+"/"+fe+"/");
		}
		return sb.toString();
		}else {
			return "";
		}
	}
}
